<template>
  <div>result:{{ getData() }}</div>
</template>

<script>
export default {
  name: "GetUrlQuery",
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      // 地址栏: http://localhost:9898/#/url?name=dengdeng&id=1
      let regExp = /.+\?(.+)/;
      let param = regExp.exec(location.href)[1];
      let paramArr = param.split("&");
      let query = {};
      paramArr.forEach((item) => {
        let itemArr = item.split("=");
        query[itemArr[0]] = decodeURI(itemArr[1]);
      });
      return query;
      //{name:'dengdeng',id:'1'}
    },
  },
};
</script>

<style scoped></style>
